import pymysql
from pymysql import cursors


class Gonju:
    @staticmethod
    def openDB(host,port,user,passwd,db):
        dbobj=pymysql.connect(host=host,port=port,user=user,password=passwd,db=db,charset='utf8')
        cursor=dbobj.cursor(cursors.DictCursor)
        return dbobj,cursor
    @staticmethod
    def readALL(sql,cousor):
        cousor.execute(sql)
        record=cousor.fetchall()
        return record
    @staticmethod
    def readONE(sql,cousor):
        cousor.execute(sql)
        record=cousor.fetchall()
        return record
    @staticmethod
    def writeDB(sql,cursor):
        result=cursor.execute(sql)
        return result
    @staticmethod
    def closeDB(dbobj):
        dbobj.close()
if __name__ == '__main__':
    host='127.0.0.1'
    port=3306
    user='root'
    passwd='123456'
    db='t_course'

    dbobj,cursor=Gonju.openDB(host,port,user,passwd,db)
    sql='insert into t_course(course_no,course_name,max_score,min_score)values("st001","软件测试",100,60),("st002","车载测试",100,60)'
    g1=Gonju()
    g1.writeDB(sql,cursor)
    dbobj.commit()



